package binary;
//补码的演示
public class ComplementDemo {
    public static void main(String[] args) {
        /*
        //规律数:
        int max = Integer.MAX_VALUE; //int的最大值
        int min = Integer.MIN_VALUE; //int的最小值
        System.out.println(Integer.toBinaryString(max));  //01111111...
        System.out.println(Integer.toBinaryString(min));  //10000000...
        System.out.println(Integer.toBinaryString(-1)); //11111111...
         */

        /*
        //负值的输出
        int n = -45;
        System.out.println(Integer.toBinaryString(n)); //以2进制输出
        int m = -11;
        System.out.println(Integer.toBinaryString(m)); //以2进制输出
        */

        /*
        //互补对称现象: -n=~n+1--->`~n=-n-1:
        int n = -7;
        int m = ~n+1;
        System.out.println(m); //7
        int i = 12;
        int j = ~i+1;
        System.out.println(j); //-12
         */

        int a = 2147483647; //int的最大值
        a = a+1;
        System.out.println(a); //-2147483648(int的最小值)

        int b = -2147483648; //int的最小值
        b = b-1;
        System.out.println(b); //2147483647

    }
}















